package notification.handler;

public class Semaphore {
	private int counter;

	public Semaphore() {
		this(0);
	}

	public Semaphore(int i) {
		if (i < 0) throw new IllegalArgumentException(i + " < 0");
		counter = i;
	}

	public synchronized void release() {
		counter++;
		this.notify();
	}

	public synchronized void acquire() throws InterruptedException {
		if (counter == 0) this.wait();
		counter--;
	}
}